import request from '@/utils/request'
import { AxiosPromise } from 'axios'
interface MenuType {
    parentId: number,
    name: string,
    href: string,
    icon: string,
    orderNum: number,
    description: string,
    shown: boolean,
    id?: string
}

const createOrUpdateMenu = (data: MenuType): AxiosPromise<any> => {
  return request({
    method: 'POST',
    url: '/boss/menu/saveOrUpdate',
    data
  })
}

const getEditMenuInfo = (id: string | number = -1): AxiosPromise<any> => {
  return request({
    method: 'GET',
    url: '/boss/menu/getEditMenuInfo',
    params: {
      id
    }
  })
}

const getAllMenus = (): AxiosPromise<any> => {
  return request({
    method: 'GET',
    url: '/boss/menu/getAll'
  })
}

const deleteMenu = (id: number): AxiosPromise<any> => {
  return request({
    method: 'DELETE',
    url: `/boss/menu/${id}`
  })
}

const getMenuNodeList = (): AxiosPromise<any> => {
  return request({
    method: 'GET',
    url: '/boss/menu/getMenuNodeList'
  })
}

interface AllocateRoleMenusType {
  roleId: number|string
  menuIdList: number[]
}

const allocateRoleMenus = (data: AllocateRoleMenusType): AxiosPromise<any> => {
  return request({
    method: 'POST',
    url: '/boss/menu/allocateRoleMenus',
    data
  })
}

export {
  createOrUpdateMenu,
  getEditMenuInfo,
  getAllMenus,
  deleteMenu,
  getMenuNodeList,
  allocateRoleMenus
}
